﻿Imports FuncClasses
Public Class BackstageCompanyItem
    Private _name As String
    'Dim xml As IDatabase
    ''' <summary>
    ''' This event is raised when the user decides to load the selected company
    ''' </summary>
    ''' <param name="companyName">The name of the Company the user wants to load</param>
    ''' <remarks></remarks>
    Public Event ChangeCompany(ByVal companyName As String)

    Public Sub New(ByVal Company As String, cs As nHibernate.Models.CompanySettingsModel)
        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        _name = Company
        'Dim cs = loader.GetCompanySettings(_name)
        Dim a As Address = cs.ToAddress
        If (String.IsNullOrEmpty(a.Street) = False OrElse String.IsNullOrEmpty(a.No) = False) Then
            Dim t As New TextBlock
            t.Foreground = Brushes.DimGray
            t.Text = a.Street + " " + a.No
            StackPanelInfo.Children.Add(t)
        End If

        If (String.IsNullOrEmpty(a.ZipCode) = False OrElse String.IsNullOrEmpty(a.City) = False) Then
            Dim t As New TextBlock
            t.Foreground = Brushes.DimGray
            t.Text = a.ZipCode + " " + a.City
            StackPanelInfo.Children.Add(t)
        End If

        If (String.IsNullOrEmpty(cs.TaxID) = False) Then
            Dim t As New TextBlock
            t.Foreground = Brushes.DimGray
            t.Text = "Steuernummer: " + cs.TaxID
            StackPanelInfo.Children.Add(t)
        End If

        If (String.IsNullOrEmpty(cs.TradeID) = False) Then
            Dim t As New TextBlock
            t.Foreground = Brushes.DimGray
            t.Text = "USt-ID: " + cs.TradeID
            StackPanelInfo.Children.Add(t)
        End If
        'xml = loader
    End Sub

    Public ReadOnly Property CompanyName As String
        Get
            Return _name
        End Get
    End Property

    Private Sub UserControl_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        SeparatorItem.Header = CompanyName
        Header = CompanyName
    End Sub

    Private Sub ChangeCompanyTab_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles ChangeCompanyTab.SelectionChanged
        Try
            If ChangeCompanyTab.SelectedItem.Equals(ChangeCompanyItem) Then

                RaiseEvent ChangeCompany(CompanyName)
            End If
        Catch ex As Exception : End Try
        Console.WriteLine(ChangeCompanyTab.SelectedIndex)
    End Sub

    Public ReadOnly Property CompanyTabControl As TabControl
        Get
            Return ChangeCompanyTab
        End Get
    End Property

    Private Sub TabItem_GotFocus(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.GotFocus
        'If xml.LastCompany <> CompanyName Then
        '    ChangeCompanyTab.SelectedIndex = -1
        'Else
        '    ChangeCompanyTab.SelectedIndex = 2
        'End If
        'Console.WriteLine(ChangeCompanyTab.SelectedIndex)

    End Sub
End Class
